package de.vl5.propellerhead.android;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.text.util.Linkify;
import android.widget.TextView;

public class AboutDialog extends Dialog {

	private static Context context = null;

	public AboutDialog(Context aContext) {
		super(aContext);
		context = aContext;

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.about);
		TextView tempTextView = (TextView) findViewById(R.id.legal_text);
		tempTextView.setText(readRawTextFile(R.raw.legal));
		tempTextView = (TextView) findViewById(R.id.info_text);
		tempTextView.setText(Html.fromHtml(readRawTextFile(R.raw.info)));
		tempTextView.setLinkTextColor(Color.BLUE);
		Linkify.addLinks(tempTextView, Linkify.ALL);

	}

	public static String readRawTextFile(int anId) {
		InputStream inputStream = context.getResources().openRawResource(anId);

		InputStreamReader tempIn = new InputStreamReader(inputStream);
		BufferedReader tempBuf = new BufferedReader(tempIn);
		String line;

		StringBuilder text = new StringBuilder();
		try {
			while ((line = tempBuf.readLine()) != null)
				text.append(line);
		} catch (IOException e) {
			return null;
		}

		return text.toString();
	}

}
